#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    int lenLongestFibSubseq(vector<int>& arr) {
        int n = arr.size();
        int ans = 0;
        vector<int> be(n),dp(n);
        for (int i = 1; i <= n; ++i)
            be[i] = arr[i] + arr[i - 1];
        for (int i = 2; i < n; ++i) {
            for (int j = i - 1; j >= 1; --j) {
                if (arr[i] == be[j])
                    dp[i] = max(dp[i], dp[j] + 1);
            }
            ans = max(ans, dp[i]);
        }
        return ans;
    }
};